<template>
  <view
    class="discussionItem animate__animated animate__bounceInRight animate__delay-0.5s"
    @click="showDiscussionDetail"
  >
    <view class="header">
      <image :src="itemDetail.author.avatar"></image>
      <view class="headInfo">
        <view class="name">{{ itemDetail.author.nickName }}</view>
        <view class="time">{{
          $formatTime.formatTimeToHHMM(itemDetail.createTime)
        }}</view>
      </view>
    </view>
    <view class="content">
      <view class="title">{{ itemDetail.title }}</view>
      <view class="text">{{ itemDetail.content }}</view>
      <view class="images" v-if="itemDetail.picList.length">
        <image
          :src="item"
          class="image"
          v-for="(item, index) in itemDetail.picList"
          :key="index"
        ></image>
      </view>
    </view>
    <view class="footer">
      <view class="categary">{{ itemDetail.categary }}</view>
      <view class="operator">
        <view class="comment">
          <image src="../../static/icons/comment.png"></image>
          <text>{{ itemDetail.commentCount }}</text>
        </view>
        <view class="like">
          <image src="../../static/icons/like.png"></image>
          <text>{{ itemDetail.liked }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: "DiscussionItem",
  props: {
    itemDetail: {
      type: Object,
      required: true,
    },
  },
  methods: {
    showDiscussionDetail() {
      const id = this.itemDetail._id;
      // 先将残留内容清空
      this.$store.commit("m_discussion/clearCurrentDiscussion");
      uni.navigateTo({
        url: `../../pages/Discussion/Discussion?id=${id}`,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.discussionItem {
  box-sizing: border-box;
  width: 700rpx;
  margin-bottom: 20rpx;
  padding: 15rpx 20rpx;
  display: flex;
  flex-direction: column;
  background-color: #fff;
  border-radius: 10rpx;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  .header {
    margin: 20rpx 0;
    display: flex;
    align-items: center;
    image {
      width: 100rpx;
      height: 100rpx;
      border-radius: 50%;
    }
    .headInfo {
      margin-left: 20rpx;
      display: flex;
      flex-direction: column;
      .name {
        font-weight: 500;
        margin-bottom: 15rpx;
      }
      .time {
        color: #aaa;
        font-size: 26rpx;
      }
    }
  }

  .content {
    width: 100%;
    display: flex;
    flex-direction: column;
    background-color: #fff;
    .title {
      font-size: 35rpx;
    }
    .text {
      width: 100%;
      text-overflow: ellipsis;
      overflow: hidden;
      display: -webkit-box;
      -webkit-line-clamp: 3;
      -webkit-box-orient: vertical;
      font-size: 30rpx;
      color: #aaa;
      margin: 20rpx 0;
    }
    .images {
      display: flex;
      .image {
        width: 210rpx;
        height: 170rpx;
        border-radius: 10rpx;
        margin-right: 10rpx;
      }
    }
  }
  .footer {
    margin-top: 30rpx;
    display: flex;
    justify-content: space-between;
    color: #aaa;
    font-size: 26rpx;
    .operator {
      display: flex;
      align-items: center;

      .comment {
        margin-right: 20rpx;
      }
      .comment,
      .like {
        display: flex;
        align-items: center;
      }
      image {
        width: 35rpx;
        height: 35rpx;
        margin-right: 10rpx;
      }
    }
  }
}
</style>
